package com.web.forum.ao.impl;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.mysteel.util.ObjectUtils;

import com.base.forum.entity.Invitation;
import com.base.forum.service.InvitationService;
import com.base.kongjian.entity.Reply;
import com.base.user.entity.Member;
import com.base.user.service.MemberService;
import com.web.forum.ao.InvitationAo;
import com.web.kongjian.ao.utils.KongjianUtils;

@Service("invitationAo")
public class InvitationAoImpl implements InvitationAo
{
	@Autowired
	private MemberService memberService;
	@Autowired
	private InvitationService invitationService;
	/*@Autowired
	private ReplyService replyService;
	@Autowired
	private ForumService forumService;*/
	

	@Override
	public void post(HttpServletRequest request, String title, String content,long forumId)
	{
		Invitation invitation = new Invitation();
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		
		invitation.setContent (content);
		invitation.setTitle (title);
		invitation.setId (System.currentTimeMillis ());
		invitation.setForumId (forumId);
		invitation.setLength (content.length ());
		invitation.setPublisherId (memberId);
		Member m = memberService.getMemberById (memberId);
		
		if(ObjectUtils.notNull (m))
		{
			invitation.setPublisherName (m.getNickName ());
			invitation.setPublisherTime (System.currentTimeMillis ());
		}
		
		invitationService.post (invitation);
	}

	@Override
	public void reply(HttpServletRequest request, long forumId, long workId,long commentId, long comment_MId, String content)
	{
		
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		
		Reply reply = new Reply ();
		reply.setComment_MId (comment_MId);
		reply.setCommentId (commentId);
		reply.setContent (content);
		reply.setReply_MId (memberId);
		reply.setReplyTime (System.currentTimeMillis ());
		
		invitationService.Replies (workId ,reply);
	}

	
}
